package ro.pub.cs.hwchecker.gui.client;

import ro.pub.cs.hwchecker.comm.client.data.Homework;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MenuPane extends Composite {
	private Hyperlink summaryLink = new Hyperlink("Summary", HWCheckerApp.APP_STATE_SUMMARY);
	private Hyperlink[] homeworkLinks = null;
	private Hyperlink gradesLink = new Hyperlink("Grades", HWCheckerApp.APP_STATE_GRADES);
	
	private VerticalPanel panel = new VerticalPanel();
	
	public MenuPane() {	
		panel.add(summaryLink);
		
		panel.add(gradesLink);
		initWidget(panel);
	}
	
	public void updateMenuPane(Homework[] homework) {
		// Remove the old homework links
		if (homeworkLinks != null) {
			for (int i = 0; i < homeworkLinks.length; i++) {
				panel.remove(homeworkLinks[i]);
			}
		}
		
		homeworkLinks = new Hyperlink[homework.length];
		
		for (int i = 0; i < homework.length; i++) {
			String appState = HWCheckerApp.composeHomeworkTabState(homework[i].id);
			
			homeworkLinks[i] = new Hyperlink(homework[i].shortName, appState);
			
			panel.insert(homeworkLinks[i], panel.getWidgetIndex(gradesLink));
			
		}
	}
}
